package com.wsj.a.collapsingdemo.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wsj.a.collapsingdemo.R;
import com.wsj.a.collapsingdemo.databinding.ItemWaterFallBinding;
import com.wsj.a.collapsingdemo.entity.WorkEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by linxiujie on 2018/8/9.
 * TODO:瀑布流里面的数据源
 */

public class WaterFallAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private List<WorkEntity> mData = new ArrayList<>();

    public WaterFallAdapter(Context context,List<WorkEntity> data){
        if(data != null){
            this.mData = data;
        }
        this.mContext = context;

    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
       ItemWaterFallBinding itemWaterFallBinding = DataBindingUtil.inflate(LayoutInflater.from(mContext),R.layout.item_water_fall,null,false);
       return new MyViewHolder(itemWaterFallBinding.getRoot());
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
       MyViewHolder myViewHolder = (MyViewHolder) holder;
       WorkEntity data = mData.get(position);
       myViewHolder.image.setImageResource(R.drawable.img_1);
       myViewHolder.image.getLayoutParams().height = data.imageHeight;
       myViewHolder.nickname.setText(data.nickname);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView image;
        private TextView nickname;

        public MyViewHolder(View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.image);
            nickname = itemView.findViewById(R.id.nickname);
        }
    }

    public List<WorkEntity> getDataList(){
        return mData;
    }

}
